package com.study.demo.service;

import com.study.demo.dto.User;
import com.study.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    @Cacheable(unless = "#result == null" , value = "login", key = "#root.args[0]")
    public User findByNameAndPassword(String name, String password) {
        return userRepository.findByNameAndPassword(name, password);
    }

    @Transactional
    public void changePwd(String name, String password, String newPwd) {
        userRepository.changePwd(name, password, newPwd);
    }
}
